package io.renren.modules.app.controller.user.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.YcUserEducationEntity;
import io.renren.modules.app.entity.YcUserResumeEntity;
import io.renren.modules.app.entity.index.YcEduBgdEntity;
import io.renren.modules.app.service.YcEduBgdService;
import io.renren.modules.app.service.YcUserEducationService;
import io.renren.modules.app.service.YcUserResumeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author lym
 * @email 928185446qq.com
 * @date 2023-12-21 17:06:24
 */
@RestController
@RequestMapping("userEducation")
public class YcUserEducationController {
    @Autowired
    private YcUserEducationService ycUserEducationService;
    @Autowired
    private YcUserResumeService ycUserResumeService;
    @Autowired
    private YcEduBgdService ycEduBgdService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
       List<YcEduBgdEntity> eduBgdList= ycEduBgdService.list();
       return R.ok().put("eduBgdList",eduBgdList);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		YcUserEducationEntity UserEducation = ycUserEducationService.getById(id);

        return R.ok().put("UserEducation", UserEducation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save( YcUserEducationEntity UserEducation, @RequestParam("userId") String userId){
		//根据userId查询用户简历信息
       YcUserResumeEntity userResume= ycUserResumeService.getOne(new QueryWrapper<YcUserResumeEntity>().eq("user_id", userId));
       //获取简历id
       int userResumeId= userResume.getId();
       UserEducation.setResumeId(userResumeId);
       UserEducation.setAddtime(new Date());
       UserEducation.setDeletestatus(false);
       ycUserEducationService.save(UserEducation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody YcUserEducationEntity ycUserEducation){
		ycUserEducationService.updateById(ycUserEducation);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		ycUserEducationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
